package cc.yaomm.service.basic.service.user;

import cc.yaomm.common.basic.domain.Paging;
import cc.yaomm.common.biz.enums.ServeTypeEnum;
import cc.yaomm.common.biz.lang.bo.ResourceBO;
import cc.yaomm.service.basic.entity.user.Resources;
import cc.yaomm.service.basic.manager.ResourceManager;
import cc.yaomm.service.basic.mapper.user.ResourcesMapper;
import cc.yaomm.service.basic.service.user.bo.ResourceParamBO;
import cc.yaomm.service.basic.service.user.bo.ResourceResultBO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;

/**
 * Created by XQL on 2021/6/9.
 */
@Service
public class ResourceService {

    @Autowired
    private ResourceManager resourceManager;

    @Autowired
    private ResourcesMapper resourcesMapper;

    public boolean refresh(ServeTypeEnum serveName, Collection<ResourceBO> resourceList) {
        return resourceManager.refresh(serveName, resourceList);
    }

    /**
     * 分页查询
     *
     * @param paramBO
     * @return
     */
    public Paging<ResourceResultBO> findPage(Paging<ResourceParamBO> paramBO) {
        Paging<Resources> paging = paramBO.convert(ResourceParamBO.class, Resources.class);
        Page<Resources> page = resourcesMapper.findPage(paging);
        Paging<ResourceResultBO> result = Paging.toPaging(page, ResourceResultBO.class);
        return result;
    }
}
